/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elsimulatorjava;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Date;

/**
 *
 * @author corey
 */
public class Application extends JFrame implements ActionListener{
    
    private JTabbedPane tabBar;
    private JPanel floorUi, elevatorUi, adminUi;
    private SimulationPanel simulationUi;
    private JButton startButton, stopButton, aEditFloorsButton, aEditElevatorsButton;
    private JTextField aNumOfFloorsLE, aNumOfElevatorsLE, aNumOfPeopleLE;
   
    //private QGridLayout floorGridLayout, elevatorGridLayout;
    private JComboBox fSelectFloor;
    private ArrayList<JButton> floorUpButton;
    private ArrayList<JButton> floorDownButton;
    private ArrayList<Integer> fPeopleOnFloor;
    private ArrayList<ArrayList<ElevatorDoorItem>> floorElevatorGraphicHolder;
    //private ArrayList<ArrayList<QGraphicsView>> floorElevatorViewHolder;
    
    private ArrayList<ElevatorPanel> elevatorDisplay;
    //private ArrayList<QGraphicsView> elevatorDisplayView;
    private JComboBox elevatorFloorList;
    private JLabel ePeopleOnElevatorL;
    private JButton callFloorButton, emergencyStop;
    private boolean eStopInitiate;
    private int prevSelectedFloor;
    private JLabel fPeopleCountSelected;
    private JLabel floorNameLabel;
    
    private Date elapsed = new Date();

    private ArrayList<Floor> floors = new ArrayList<Floor>();
    private ArrayList<Elevator> elevators;
    
    private Building b;
    private Thread t;
    
    private FloorDialog floorDialog;
    private ElevatorDialog elevatorDialog;

    boolean paused;
    
    public Application(){
        this.setTitle("Yeroc elSimulator");
        this.setSize(800, 600);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        //QValidator numbersOnly = new QIntValidator(0, 999, this);
        aEditFloorsButton = new JButton("Edit");
        aEditFloorsButton.addActionListener(new ActionListener() {
            
            public void actionPerformed(ActionEvent e)
            {
                
                Floor.resetIndex();
                if (!aNumOfFloorsLE.getText().isEmpty() && Integer.parseInt(aNumOfFloorsLE.getText()) > 1){
                    floorDialog = new FloorDialog(Integer.parseInt(aNumOfFloorsLE.getText()));
                    floors = new ArrayList<Floor>();
                    floorDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                    floorDialog.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent we) {
                            System.out.println("ble");
                        }
                    });
                    floorDialog.setVisible(true);
                    /*if (floorDialog.setVisible(true) == 0){
                        this.floors = floorDialog.getFloors();
                        //aNumOfElevatorsLE.setFocus();
                    }*/
                } else {
                    //MessageBox msgBox = new QMessageBox();
                    //msgBox.setText("At least two floors are required.");
                    //msgBox.setIcon(QMessageBox.Icon.Warning);
                    //msgBox.exec();
                }
                elevators = new ArrayList<Elevator>();
                
            }
        }); 
        aEditElevatorsButton = new JButton("Edit");
        aEditElevatorsButton.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e)
            {
                //Execute when button is pressed
                System.out.println("You clicked the button");
            }
        }); 
        aNumOfFloorsLE = new JTextField();
        //aNumOfFloorsLE.setValidator(numbersOnly);
        //aNumOfFloorsLE.setAlignment(Qt.AlignmentFlag.AlignRight);
        aNumOfElevatorsLE = new JTextField();
        //aNumOfElevatorsLE.setValidator(numbersOnly);
        aNumOfFloorsLE.setSize(aNumOfFloorsLE.getHeight(), 300);
        aNumOfElevatorsLE.setSize(aNumOfElevatorsLE.getHeight(), 300);
        //aNumOfElevatorsLE.setAlignment(Qt.AlignmentFlag.AlignRight);
        aNumOfPeopleLE = new JTextField();
        //aNumOfPeopleLE.setValidator(numbersOnly);
        aNumOfPeopleLE.setSize(aNumOfPeopleLE.getHeight(), 300);
        //aNumOfPeopleLE.setAlignment(Qt.AlignmentFlag.AlignRight);
        //aNumOfFloorsLE.setText("0");
        aNumOfElevatorsLE.setText("1");
        aNumOfElevatorsLE.setEnabled(false);
        
        stopButton = new JButton("Stop Simulation");
        stopButton.setEnabled(false);
        stopButton.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e)
            {
                //Execute when button is pressed
                System.out.println("You clicked the button");
            }
        }); 
        startButton = new JButton("Start Simulation");
        startButton.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e)
            {
                //Execute when button is pressed
                System.out.println("You clicked the button");
            }
        }); 
        
       /* saveButton = new QPushButton("Save", adminUi);
        saveButton.setFixedWidth(200);
        saveButton.clicked.connect(this, "saveButtonClicked()");*/
        
        //adminGridLayout.setColumnMinimumWidth(1, 0);
        //adminGridLayout.setAlignment(new Qt.Alignment(Qt.AlignmentFlag.AlignLeft));
        /*adminGridLayout.addWidget(new JLabel("Number of floors", adminUi), 0, 0, Qt.AlignmentFlag.AlignRight);
        adminGridLayout.addWidget(aNumOfFloorsLE, 0, 1);
        adminGridLayout.addWidget(aEditFloorsButton, 0, 2);
        aEditFloorsButton.clicked.connect(this, "aEditFloorsClicked()");
        aEditElevatorsButton.clicked.connect(this, "aEditElevatorsClicked()");
        adminGridLayout.addWidget(new JLabel("Number of elevators", adminUi), 1, 0, Qt.AlignmentFlag.AlignRight);
        adminGridLayout.addWidget(aNumOfElevatorsLE, 1, 1);
        adminGridLayout.addWidget(aEditElevatorsButton, 1, 2);
        adminGridLayout.addWidget(new JLabel("Number of AI people"), 2, 0, Qt.AlignmentFlag.AlignRight);
        adminGridLayout.addWidget(aNumOfPeopleLE, 2, 1);
        adminGridLayout.addWidget(stopButton, 3, 0, 3, 1, Qt.AlignmentFlag.AlignRight);
        adminGridLayout.addWidget(startButton, 3, 2, 3, 4, Qt.AlignmentFlag.AlignLeft);
        adminUi.setLayout(adminGridLayout);*/
        
        tabBar = new JTabbedPane();
        //tabBar.move(10, 10);

        //buildingUi = new JPanel();
        adminUi = new JPanel();
        JPanel adminFormPanel = new JPanel();
        
        adminUi.setLayout(new BoxLayout(adminUi, BoxLayout.Y_AXIS));
        
        GridLayout formGridLayout = new GridLayout(0,3);
        formGridLayout.setHgap(30);
        formGridLayout.setVgap(0);
        adminFormPanel.setLayout(formGridLayout);
        adminFormPanel.add(new JLabel("Number of floors"));
        adminFormPanel.add(aNumOfFloorsLE);
        adminFormPanel.add(aEditFloorsButton);
        adminFormPanel.add(new JLabel("Number of elevators"));
        adminFormPanel.add(aNumOfElevatorsLE);
        adminFormPanel.add(aEditElevatorsButton);
        
        GridLayout buttonGridLayout = new GridLayout(1,2);
        JPanel adminButtonPanel = new JPanel();
        adminButtonPanel.setLayout(buttonGridLayout);
        adminButtonPanel.add(stopButton);
        adminButtonPanel.add(startButton);
        
        adminUi.add(adminFormPanel);
        adminUi.add(Box.createVerticalStrut(430));
        adminUi.add(adminButtonPanel);
        
      
       // bPeopleCountLabel = new JLabel("People: ", buildingUi);
        //bPeopleCountLabel.setFixedSize(100, 20);
        
        tabBar.setSize(780, 580);
        tabBar.addTab("Admin", adminUi);
        this.add(tabBar);
        //tabBar.addTab(buildingUi, "Building");
        //tabBar.addTab(floorUi, "Floor");
        //tabBar.addTab(elevatorUi, "Elevator");
        this.setVisible(true);
    }
    
        private void openFloorDialog(){
        Floor.resetIndex();
        if (!this.aNumOfFloorsLE.getText().isEmpty() && Integer.parseInt(this.aNumOfFloorsLE.getText()) > 1){
            floorDialog = new FloorDialog(Integer.parseInt(this.aNumOfFloorsLE.getText()));
            this.floors = new ArrayList<Floor>();
            floorDialog.setVisible(true);
            /*if (floorDialog.setVisible(true) == 0){
                this.floors = floorDialog.getFloors();
                //aNumOfElevatorsLE.setFocus();
            }*/
        } else {
            //MessageBox msgBox = new QMessageBox();
            //msgBox.setText("At least two floors are required.");
            //msgBox.setIcon(QMessageBox.Icon.Warning);
            //msgBox.exec();
        }
        this.elevators = new ArrayList<Elevator>();
    }
    
    private void startButtonClicked(){
        
        if (!this.elevators.isEmpty() && !this.floors.isEmpty()){
        
        floorUi = new JPanel();
        elevatorUi = new JPanel();
            
        //floorGridLayout = new QGridLayout();
        //elevatorGridLayout = new QGridLayout();
        if (!aNumOfPeopleLE.getText().isEmpty()){
            b = new Building(this.elevators, this.floors, Integer.parseInt(aNumOfPeopleLE.getText()));
        } else {
            b = new Building(this.elevators, this.floors);
        }
        
        // Puts simulation panel there!
        simulationUi = new SimulationPanel(b.getElevators());

        this.setAdminFields(false);
        // Set up floor
        fSelectFloor = new JComboBox();
        //upButton = new JButton("Up", floorUi);
        //upButton.clicked.connect(this, "upButtonClicked()");
        //downButton = new JButton("Down", floorUi);
        //downButton.clicked.connect(this, "downButtonClicked()");
        fPeopleOnFloor = new ArrayList<Integer>();
        
        fPeopleCountSelected = new JLabel("");
        floorNameLabel = new JLabel("");
        //floorGridLayout.setColumnMinimumWidth(1, 0);
        //floorGridLayout.setColumnMinimumWidth(1, 0);
        /*floorGridLayout.addWidget(new JLabel("Select Floor"), 0, 0, Qt.AlignmentFlag.AlignRight);
        floorGridLayout.addWidget(fSelectFloor, 0, 1);
        floorGridLayout.addWidget(floorNameLabel, 0, 2);*/
        //floorGridLayout.addWidget(upButton, 0, 3);
        //floorGridLayout.addWidget(downButton, 1, 3);
        //floorGridLayout.addWidget(fPeopleCountSelected, 1, 1);
       /* floorUi.setLayout(floorGridLayout);
        elevatorUi.setLayout(elevatorGridLayout);*/
            
        //elevatorDoorGraphic = new ArrayList<ElevatorDoorItem>();
        //elevatorDoorView = new ArrayList<QGraphicsView>();
        
        floorElevatorGraphicHolder = new ArrayList<ArrayList<ElevatorDoorItem>>();
        //floorElevatorViewHolder = new ArrayList<ArrayList<QGraphicsView>>();
        floorUpButton = new ArrayList<JButton>();
        floorDownButton = new ArrayList<JButton>();
        
        elevatorDisplay = new ArrayList<ElevatorPanel>();
        //elevatorDisplayView = new ArrayList<QGraphicsView>();
        ePeopleOnElevatorL = new JLabel("People: 0");
        elevatorFloorList = new JComboBox();
        callFloorButton = new JButton("Go to");
        //callFloorButton.clicked.connect(this, "callElevatorClicked()");
        emergencyStop = new JButton("Emergency Stop!");
        //emergencyStop.clicked.connect(this, "emergencyStopClicked()");
        eStopInitiate = false;
        
        /*floorGridLayout.addWidget(fPeopleCountSelected, 1, 1);

        elevatorGridLayout.addWidget(new JLabel("Floor"), 0, 0, Qt.AlignmentFlag.AlignRight);
        elevatorGridLayout.addWidget(elevatorFloorList, 0, 1);
        elevatorGridLayout.addWidget(callFloorButton, 0, 2);
        elevatorGridLayout.addWidget(ePeopleOnElevatorL, 0, 3);
        elevatorGridLayout.addWidget(emergencyStop, 0, 4);*/
        
        for (int i = 0; i < this.floors.size(); i++){
            
           /* elevatorDoorGraphic.add(new ElevatorDoorItem());
            QGraphicsScene scene = new QGraphicsScene(this);

            scene.setItemIndexMethod(QGraphicsScene.ItemIndexMethod.NoIndex);
            scene.addItem(elevatorDoorGraphic.get(i));
            elevatorDoorView.add(new QGraphicsView(scene));
            elevatorDoorView.get(i).setFixedSize(400, 300);*/
            fSelectFloor.addItem(String.valueOf(i));
            fPeopleOnFloor.add(0);
            
            floorElevatorGraphicHolder.add(new ArrayList<ElevatorDoorItem>());
           // floorElevatorViewHolder.add(new ArrayList<QGraphicsView>());

          //  b.getFloors().get(i).numberOfPeopleChanged.connect(this, "setNumberOfPeople(int,int)");
            
        }
      /*  for (int i = 0; i < b.getElevatorCount(); i++){
            elevatorDisplay.add(new ElevatorPanel(i));
           // QGraphicsScene sc = new QGraphicsScene(this);
            //sc.setItemIndexMethod(QGraphicsScene.ItemIndexMethod.NoIndex);
            //sc.addItem(elevatorDisplay.get(i));
            /*elevatorDisplayView.add(new QGraphicsView(sc));
            elevatorDisplayView.get(i).setFixedSize(500, 300);
            elevatorGridLayout.addWidget(elevatorDisplayView.get(i), 1, 0, 1, 4);
             b.setCurrentFloorEmitter(i, this, "setCurrentFloor(int,int)");
             b.setDoorStateEmitter(i, this, "setDoorState(int,boolean)");
             b.setDirectionEmitter(i, this, "setDirection(int,boolean)");
             b.setPeopleCountEmitter(i, this, "setPeopleInElevator(int,int)");


             
             elevatorDisplay.add(new ElevatorPanel(i));
             
             
             for (int j = 0; j < this.floors.size(); j++){
                 floorUpButton.add(new JButton("Up", floorUi));
                 floorDownButton.add(new JButton("Down", floorUi));
                 floorUpButton.get(j).clicked.connect(this, "upButtonClicked()");
                 floorDownButton.get(j).clicked.connect(this, "downButtonClicked()");
                 floorUpButton.get(j).hide();
                 floorDownButton.get(j).hide();
                 floorGridLayout.addWidget(floorUpButton.get(j), 0, 4);
                 floorGridLayout.addWidget(floorDownButton.get(j), 1, 4);
                 
                 if (j == this.floors.size()-1){
                        floorUpButton.get(j).setEnabled(false);
                     }
                     if (j == 0){
                         floorDownButton.get(j).setEnabled(false);
                     }
                 
                 if (b.getElevatorGoToFloor(i, j)){
                     floorElevatorGraphicHolder.get(j).add(new ElevatorDoorItem(i));
                     floorElevatorGraphicHolder.get(j).get(i).updateFloorUi.connect(this, "updateFloorUi(int)");
                     QGraphicsScene scene = new QGraphicsScene(this);
                     scene.setItemIndexMethod(QGraphicsScene.ItemIndexMethod.NoIndex);
                     scene.addItem(floorElevatorGraphicHolder.get(j).get(i));
                     floorElevatorViewHolder.get(j).add(new QGraphicsView(scene));
                     floorElevatorViewHolder.get(j).get(i).setFixedSize(400, 300);
                     floorGridLayout.addWidget(floorElevatorViewHolder.get(j).get(i), 2, i, 2, 5);
                     floorElevatorViewHolder.get(j).get(i).hide();
                     elevatorFloorList.addItem(String.valueOf(j));
                 }
             }
             this.setCurrentFloor(i, b.getElevatorCurrentFloor(i));
             this.setDirection(i, b.isElevatorGoingUp(i));
        }
        
//            b.createPerson(3, 4);
//            b.createPerson(1, 2);
//            b.createPerson(5, 1);
//            b.createPerson(0, 5);
//            b.createPerson(5, 2);
//            b.createPerson(4, 0);
        // Initially selected 0
            prevSelectedFloor = 0;
            this.fSelectFloorIndexChanged();
        fSelectFloor.currentIndexChanged.connect(this, "fSelectFloorIndexChanged()");

        floorGridLayout.addWidget(fPeopleCountSelected, 1, 1);
        
            t = new Thread(b);
            
            t.setDaemon(true);
            t.start();
            tabBar.addTab(floorUi, "Floor");
            tabBar.setCurrentIndex(1);
            tabBar.addTab(elevatorUi, "Elevator");
            startButton.setEnabled(false);
            stopButton.setEnabled(true);
            
            } else {
                QMessageBox msgBox = new QMessageBox();
                msgBox.setText("You must first up your floors and elevators.");
                msgBox.setIcon(QMessageBox.Icon.Warning);
                msgBox.exec();
            }


    }
    
    private void stopButtonClicked(){
        startButton.setEnabled(true);
        stopButton.setEnabled(false);
        this.setAdminFields(true);
        this.clean();

        this.floors = new ArrayList<Floor>();
        this.elevators = new ArrayList<Elevator>();
            
        tabBar.removeTab(1);
        tabBar.removeTab(1);
        
        b.stop();
    }
    
    private void setCurrentFloor(int idx, int cFloor){
        //eCurrentFloorLabel.get(idx).setText("Current Floor: " + cFloor);
        for (int i = 0; i < floorElevatorGraphicHolder.size(); i++){
            for (int j = 0; j < floorElevatorGraphicHolder.get(i).size(); j++){
                if (floorElevatorGraphicHolder.get(i).get(j).getIndex() == idx){
                    floorElevatorGraphicHolder.get(i).get(j).setFloorNumber(cFloor);
                }
            }
        }
        
        if (b.isElevatorGoingUp(idx)){
            if (b.getElevatorCurrentFloor(idx) == fSelectFloor.currentIndex() && !floorUpButton.get(b.getElevatorCurrentFloor(idx)).isEnabled()){
            tabBar.setCurrentIndex(2);
            } 
            if (cFloor != this.floors.size()-1){
                floorUpButton.get(b.getElevatorCurrentFloor(idx)).setEnabled(true);
            }
        } else if (!b.isElevatorGoingUp(idx)){
            if (b.getElevatorCurrentFloor(idx) == fSelectFloor.currentIndex() && !floorDownButton.get(b.getElevatorCurrentFloor(idx)).isEnabled()){
                tabBar.setCurrentIndex(2);
            }
            if (cFloor != 0){
                floorDownButton.get(b.getElevatorCurrentFloor(idx)).setEnabled(true);
            }
        }
        for (int i = 0; i < elevatorDisplay.size(); i++){
            elevatorDisplay.get(i).setFloorNumber(cFloor);
        }
    }
    
    private void setNumberOfPeople(int idx, int pCount){
        fPeopleOnFloor.set(idx, pCount);
        fPeopleCountSelected.setText("People: " + fPeopleOnFloor.get(fSelectFloor.currentIndex()).toString());
        fPeopleCountSelected.update();
    }
    
    private void setDoorState(int idx, boolean state){
        for (int i = 0; i < floorElevatorGraphicHolder.size(); i++){
            for (int j = 0; j < floorElevatorGraphicHolder.get(i).size(); j++){
                if (b.getElevatorCurrentFloor(idx) == i && b.getElevatorGoToFloor(idx, i) &&
                floorElevatorGraphicHolder.get(i).get(j).getIndex() == idx){
                    
                    do{
                        if (new Date().getTime() - elapsed.getTime() > 5){
                            floorElevatorGraphicHolder.get(i).get(j).setDoorClosed(state);
                            this.update();
                            elapsed = new Date();
                        }
                    } while(!floorElevatorGraphicHolder.get(i).get(j).isOpenOrClosed());
                    
                    //System.out.println("idx: " + idx + " i: " + i + " state: " + state);
                }
            }
        }
        for (int i = 0; i < elevatorDisplay.size(); i++){
            elevatorDisplay.get(i).setDoorClosed(state);
        }
        
    }
    
    private void setDirection(int idx, boolean state){
        for (int i = 0; i < floorElevatorGraphicHolder.size(); i++){
            for (int j = 0; j < floorElevatorGraphicHolder.get(i).size(); j++){
                if (b.getElevatorGoToFloor(idx, i) &&
                        floorElevatorGraphicHolder.get(i).get(j).getIndex() == idx){
                    floorElevatorGraphicHolder.get(i).get(j).setDirectionUp(state);
                    //System.out.println("idx: " + idx + " i: " + i + " state: " + state);
                }
            }
        }
        for (int i = 0; i < elevatorDisplay.size(); i++){
            elevatorDisplay.get(i).setDirectionUp(state);
        }
        
    }
    
    private void setPeopleInElevator(int idx, int pCount){
        ePeopleOnElevatorL.setText("People: " + pCount);
    }
    
    private void aEditFloorsClicked(){
        Floor.resetIndex();
        if (!this.aNumOfFloorsLE.text().isEmpty() && Integer.parseInt(this.aNumOfFloorsLE.text()) > 1){
            floorDialog = new FloorDialog(Integer.parseInt(this.aNumOfFloorsLE.text()));
            this.floors = new ArrayList<Floor>();
            if (floorDialog.exec() == 0){
                this.floors = floorDialog.getFloors();
                //aNumOfElevatorsLE.setFocus();
            }
        } else {
            QMessageBox msgBox = new QMessageBox();
            msgBox.setText("At least two floors are required.");
            msgBox.setIcon(QMessageBox.Icon.Warning);
            msgBox.exec();
        }
        this.elevators = new ArrayList<Elevator>();
    }

    private void aEditElevatorsClicked(){
        Elevator.resetIndex();
         if (!this.aNumOfFloorsLE.text().isEmpty() && Integer.parseInt(this.aNumOfFloorsLE.text()) > 0){
             elevatorDialog = new ElevatorDialog(Integer.parseInt(this.aNumOfElevatorsLE.text()), this.floors.size());
             if (elevatorDialog.exec() == 0){
                 this.elevators = elevatorDialog.getElevators();
             }
         }
    }
    //TODO
    private void callElevatorClicked(){
        this.b.elevatorCall(0, elevatorFloorList.currentIndex());
    }
    
    private void emergencyStopClicked(){
        if (!eStopInitiate){
            this.b.setStopElevator(0, true);
            emergencyStop.setText("Resume");
            eStopInitiate = true;
        } else {
            this.b.setStopElevator(0, false);
            emergencyStop.setText("Emergency Stop!");
            eStopInitiate = false;
        }
    }
    
    private void upButtonClicked(){
        if(b.requestElevator(true, fSelectFloor.currentIndex())){
            floorUpButton.get(fSelectFloor.currentIndex()).setEnabled(false);
        }
    }
    
    private void downButtonClicked(){
        if (b.requestElevator(false, fSelectFloor.currentIndex())){
            floorDownButton.get(fSelectFloor.currentIndex()).setEnabled(false);
        }
    }

    private void saveButtonClicked() throws Exception {
        b.stop();
        b.save();
        b.start();
    }
    
    private void updateFloorUi(int idx){
            //this.elevatorDisplayView.get(idx).repaint();
            for (int i = 0; i < b.getNumberOfFloors(); i++){
                for (int j = 0; j < b.getElevatorCount(); j++){
                    this.floorElevatorGraphicHolder.get(i).get(j).update();
                    this.floorElevatorViewHolder.get(i).get(j).update();
                    this.floorUi.update();
                }
            }

    }

    private void fSelectFloorIndexChanged(){
        fPeopleCountSelected.setText("People: " + fPeopleOnFloor.get(fSelectFloor.currentIndex()));
        floorNameLabel.setText(floors.get(fSelectFloor.currentIndex()).getFloorName());
        floorNameLabel.update();
        fPeopleCountSelected.update();
        if (fSelectFloor.currentIndex() >= 0){
            //floorGridLayout.removeWidget(fPeopleOnFloorLabel.get(prevSelectedFloor));
            floorUpButton.get(prevSelectedFloor).hide();
            floorDownButton.get(prevSelectedFloor).hide();
            floorDownButton.get(fSelectFloor.currentIndex()).show();
            floorUpButton.get(fSelectFloor.currentIndex()).show();
        for (int i = 0; i < floorElevatorViewHolder.get(prevSelectedFloor).size(); i++){
            //floorGridLayout.removeWidget(floorElevatorViewHolder.get(prevSelectedFloor).get(i));
            floorElevatorViewHolder.get(prevSelectedFloor).get(i).hide();
        }
        for (int i = 0; i < floorElevatorViewHolder.get(fSelectFloor.currentIndex()).size(); i++){
            //floorGridLayout.addWidget(floorElevatorViewHolder.get(fSelectFloor.currentIndex()).get(i), 2, i);
            floorElevatorViewHolder.get(fSelectFloor.currentIndex()).get(i).show();
        }
        prevSelectedFloor = fSelectFloor.currentIndex();
        }
        //floorGridLayout.addWidget(fPeopleCountSelected, 1, 1);*/
        /*    
        for (int i = 0; i < fElevatorGroupBox.size(); i++){
            floorGridLayout.removeWidget(fElevatorGroupBox.get(i));
        }
        for (int i = 0; i < elevators.size(); i++){
            int j = 0;
            if (elevators.get(i).goesToFloor(fSelectFloor.currentIndex())){
                floorGridLayout.addWidget(fElevatorGroupBox.get(i), 2, j);
                j++;
            }*/
        }
    }
    
    private void clean(){
        elevatorUi = new JPanel();
        floorUi = new JPanel();
        //floorGridLayout = new QGridLayout();
    }
    
    
    private void setAdminFields(boolean value){
        aNumOfFloorsLE.setEnabled(value);
        aEditFloorsButton.setEnabled(value);
        aNumOfElevatorsLE.setEnabled(value);
        aEditElevatorsButton.setEnabled(value);
        aNumOfPeopleLE.setEnabled(value);
    }

    public void actionPerformed(ActionEvent ae) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

